package com.yc.demo.d0303;

import com.yc.demo.util.VerifyCodeUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "vcode.s", value = "/vcode.s")
public class VcodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 必须在输出验证码之前获取会话对象
        HttpSession session = request.getSession();
        // 生成验证码，同时向页面输出验证码图片
        String vcode = VerifyCodeUtils.outputImage(response);
        // 将验证码保存到会话中
        session.setAttribute("vcode", vcode);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
